package per.destiny.seckill.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private UserArgumentResolver userArgumentResolver;

    @Autowired
    private AccessLimitInterceptor accessLimitInterceptor;

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        resolvers.add(userArgumentResolver);
    }


    //某些版本的SpringBoot当配置了WebConfig之后，静态资源文件就找不到了，需要通过如下进行配置。
//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
//    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(accessLimitInterceptor)
                //使用"/static/**"不生效,是因为static相当于是根目录，实际访问，这块写的不好,推荐用一个统一的静态目录
                .excludePathPatterns("/*.htm",
                        "/bootstrap-3.4.1/**",
                        "/css/**", "/img/**",
                        "/jquery*/**",
                        "/js/**",
                        "/md5/**");
    }
}
